package com.common.widget;

import android.content.Context;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.common.R;

/**
 * Created by cms on 2017/1/11.
 */

public class NetworkToast {

    final Context mContext;
    final android.widget.Toast customToast;


    public NetworkToast(Context mContext, android.widget.Toast customToast) {
        this.mContext = mContext;
        this.customToast = customToast;
    }

    public static NetworkToast makeText(Context context) {

        android.widget.Toast customToast = new android.widget.Toast(context);
        customToast.setDuration(1000);
        customToast.setGravity(Gravity.CENTER, 0, 0);
        LinearLayout linearLayout = new LinearLayout(context);
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        ImageView imageView = new ImageView(context);

        imageView.setBackgroundResource(R.drawable.ic_network_not_available);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

        imageView.setLayoutParams(layoutParams);

        linearLayout.addView(imageView);

        customToast.setView(linearLayout);
        NetworkToast result = new NetworkToast(context, customToast);
        return result;
    }


    public void show() {
        customToast.show();
    }

}
